//
//  VisitorView.m
//  WisdomCommunity
//
//  Created by Yahaong on 16/7/26.
//  Copyright © 2016年 zonten. All rights reserved.
//

#import "VisitorView.h"
#import "YHMarcros.h"

@interface VisitorView ()
/** 访客姓氏 */
@property(nonatomic, strong)UILabel *visitorSurnameLabel;
/** 访客姓氏输入框 */
@property(nonatomic, strong)UITextField *visitorSurnameTextField;
/** 访客性别 */
@property(nonatomic, strong)UILabel *visitorSex;
/** 访客性别选择 */
@property(nonatomic, strong)UISegmentedControl *visitorSexControl;
/** 驾车来访 */
@property(nonatomic, strong)UILabel *isDrivingLabel;
/** 驾车来访Button */
@property(nonatomic, strong)UIButton *isDrivingView ;
/** 到访时间 */
@property(nonatomic, strong)UILabel *timeLabel;
/** 到访时间Button */
@property(nonatomic, strong)UIButton *timeButton;

@end
@implementation VisitorView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.visitorSurnameLabel];
    
    [self.visitorSurnameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.leading.equalTo(self).offset(10);
        make.height.equalTo(self).multipliedBy(0.25);
    }];
    [self addSubview:self.visitorSurnameTextField];
    [self.visitorSurnameTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.leading.equalTo(self.visitorSurnameLabel.trailing).offset(20);
        make.height.equalTo(self.visitorSurnameLabel);
    }];
    
    UIView *surnameSplitView = [[UIView alloc]init];
    surnameSplitView.backgroundColor = kSplitLineColor;
    [self addSubview:surnameSplitView];
    [surnameSplitView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.visitorSurnameLabel.bottom);
        make.leading.trailing.equalTo(self);
        make.height.equalTo(1);
    }];
    
    
    [self addSubview:self.visitorSex];
    [self.visitorSex mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(surnameSplitView.bottom);
        make.leading.equalTo(self.visitorSurnameLabel.leading);
        make.height.equalTo(self.visitorSurnameLabel.height);
    }];
    [self addSubview:self.visitorSexControl];
    [self.visitorSexControl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(70);
        make.height.equalTo(25);
        make.centerY.equalTo(self.visitorSex);
        make.trailing.equalTo(self).offset(-8);
    }];
    
    UIView *sexSplitView = [[UIView alloc]init];
    sexSplitView.backgroundColor = kSplitLineColor;
    [self addSubview:sexSplitView];
    [sexSplitView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.visitorSex.bottom);
        make.leading.trailing.equalTo(self);
        make.height.equalTo(1);
    }];
    
    
    [self addSubview:self.isDrivingLabel];
    [self.isDrivingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(sexSplitView.bottom);
        make.leading.equalTo(self.visitorSurnameLabel.leading);
        make.height.equalTo(self.visitorSurnameLabel.height);
    }];
    
    [self addSubview:self.isDrivingView];
    [self.isDrivingView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self).offset(-8);
        make.centerY.equalTo(self.isDrivingLabel);
    }];
    
    UIView *isDrivingSplitView = [[UIView alloc]init];
    isDrivingSplitView.backgroundColor = kSplitLineColor;
    [self addSubview:isDrivingSplitView];
    [isDrivingSplitView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.isDrivingLabel.bottom);
        make.leading.trailing.equalTo(self);
        make.height.equalTo(1);
    }];
    
    [self addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(isDrivingSplitView.bottom);
        make.leading.equalTo(self.visitorSurnameLabel.leading);
        make.height.equalTo(self.visitorSurnameLabel.height);
    }];
    
    [self addSubview:self.timeButton];
    
    
    [self.timeButton mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.equalTo(self.timeLabel);
        make.trailing.equalTo(self).offset(-8);
    }];

    

}

- (UILabel *)visitorSurnameLabel
{
    if (!_visitorSurnameLabel) {
        _visitorSurnameLabel = [[UILabel alloc]init];
        _visitorSurnameLabel.text = @"访客姓氏";
    }
    return _visitorSurnameLabel;
}

- (UITextField *)visitorSurnameTextField
{
    if (!_visitorSurnameTextField) {
        _visitorSurnameTextField = [[UITextField alloc]init];
        _visitorSurnameTextField.placeholder = @"请输入访客姓氏";
    }
    return _visitorSurnameTextField;
}

- (UILabel *)visitorSex
{
    if(!_visitorSex)
    {
        _visitorSex = [[UILabel alloc]init];
        _visitorSex.text = @"访问性别";
    }
    return _visitorSex;
}
- (UISegmentedControl *)visitorSexControl
{
    if (!_visitorSexControl) {
        _visitorSexControl = [[UISegmentedControl alloc]initWithItems:@[@"先生",@"女士"]];
        _visitorSexControl.layer.cornerRadius = 12;
        _visitorSexControl.layer.masksToBounds =YES;
        _visitorSexControl.backgroundColor = [UIColor whiteColor];
        _visitorSexControl.tintColor = kGlobalRedColor;
        _visitorSexControl.layer.borderColor = kGlobalRedColor.CGColor;
        _visitorSexControl.layer.borderWidth = 1;
//        _visitorSexControl.tintColor = [UIColor whiteColor];
        _visitorSexControl.selectedSegmentIndex = 0;
  
        //        [_visitorSexControl addTarget:self action:@selector(segmentedClick:) forControlEvents:UIControlEventValueChanged];
        
    }
    return _visitorSexControl;
}
- (UILabel *)isDrivingLabel
{
    if(!_isDrivingLabel)
    {
        _isDrivingLabel = [[UILabel alloc]init];
        _isDrivingLabel.text = @"驾车来访";
    }
    return _isDrivingLabel;
}
- (UIButton *)isDrivingView
{
    if (!_isDrivingView) {
        _isDrivingView = [[UIButton alloc]init];
        [_isDrivingView setImage:[UIImage imageNamed:@"property_icon_selected"] forState:UIControlStateSelected];
        [_isDrivingView setImage:[UIImage imageNamed:@"property_icon_normal"] forState:UIControlStateNormal];
        _isDrivingView.selected = YES;

    }
    return _isDrivingView;
}

- (UILabel *)timeLabel
{
    if(!_timeLabel)
    {
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.text = @"到访时间";
    }
    return _timeLabel;
}
- (UIButton *)timeButton
{
    if(!_timeButton)
    {
        _timeButton = [[UIButton alloc]init];
        [_timeButton setTitle:@"2017-6-23" forState:UIControlStateNormal];
        [_timeButton setTitleColor:RGBColor(153, 153, 153) forState:UIControlStateNormal];
    }
    return _timeButton;
}

@end
